<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="education">
        <el-input
          v-model="queryParams.education"
          placeholder="请输入学历"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前状态" prop="currentState">
        <el-input
          v-model="queryParams.currentState"
          placeholder="请输入:在职 待业 再读"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="顾问老师" prop="teacher">
        <el-input
          v-model="queryParams.teacher"
          placeholder="请输入顾问老师"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:student:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:student:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:student:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:student:export']"
        >导出</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 新增学员协议功能组件 -->
    <infofile :type="buttontype.infofile" :fun="showbtn" tname="infofile" :tablerow="tablerow" ></infofile>
    

    <el-table v-loading="loading" :data="filterArr" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="name" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column label="是否签订协议" align="center" prop="isSignProtpcpl" />
      <el-table-column label="前端阶段" align="center" prop="frontStage" />
      <el-table-column label="班级名称" align="center" prop="className" />
      <!-- <el-table-column label="协议路径" align="center" prop="className" /> -->
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="身份证" align="center" prop="idCard" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="详细地址" align="center" prop="addressInfo" />
      <el-table-column label="出生日期" align="center" prop="birthDate" />
      <el-table-column label="学历" align="center" prop="education" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="微信号" align="center" prop="wechat" />
      <el-table-column label="qq" align="center" prop="qq" />
      <el-table-column label="当前状态" align="center" prop="currentState" />
      <el-table-column label="目标就业城市" align="center" prop="city" />
      <el-table-column label="紧急联系人" align="center" prop="emergencyContact" />
      <el-table-column label="紧急联系人电话" align="center" prop="emergencyPhone" />
      <el-table-column label="顾问老师" align="center" prop="teacher" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:student:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-goods"
            @click="infofile(scope.row)"
            v-hasPermi="['system:protpcpl:query']"
          >查看协议</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:student:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学员档案信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>  
        <el-form-item label="前端阶段" prop="frontStage">
          <el-input v-model="form.frontStage" placeholder="请输入前端阶段" />
        </el-form-item>
        <el-form-item label="班级名称" prop="className">
          <el-input v-model="form.className" placeholder="请输入班级名称" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="身份证" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="详细地址" prop="addressInfo">
          <el-input v-model="form.addressInfo" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-input v-model="form.birthDate" placeholder="请输入出生日期" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="微信号" prop="wechat">
          <el-input v-model="form.wechat" placeholder="请输入微信号" />
        </el-form-item>
        <el-form-item label="qq" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入qq" />
        </el-form-item>
        <el-form-item label="当前状态" prop="currentState">
          <el-input v-model="form.currentState" placeholder="请输入当前状态：在职 待业 再读" />
        </el-form-item>
        <el-form-item label="目标就业城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入当前状态：在职 待业 再读" />
        </el-form-item>
        <el-form-item label="紧急联系人" prop="emergencyContact">
          <el-input v-model="form.emergencyContact" placeholder="请输入紧急联系人" />
        </el-form-item>
        <el-form-item label="紧急联系人电话" prop="emergencyPhone">
          <el-input v-model="form.emergencyPhone" placeholder="请输入紧急联系人电话" />
        </el-form-item>
        <el-form-item label="顾问老师" prop="teacher">
          <el-input v-model="form.teacher" placeholder="请输入顾问老师" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/system/info";

import Infofile from "./Infofile";
import {Bus} from '@/utils/bus'
export default {
  name: "Info",
  data() {
    return {
      id:'',//学员id
      tablerow: '', // 当前选中的用户
      //新增学员协议模态框状态
      buttontype: {
        infofile:false,
      },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id:null,//学员id
        name: null,//姓名
        gender: null,//性别
        idCard: null,//身份证号码
        phone: null,//手机号码
        frontStage: null,//前端阶段
        familyAddress: null,//家庭住址
        birthDate: null,//出生日期
        education: null,//学历
        major: null,//专业
        wechat: null,//微信号
        qq: null,//qq号码
        currentState: null, //目前状态
        city: null,//目标就业城市
        emergencyContact: null,//紧急联系人
        emergencyPhone: null,//紧急联系人电话
        teacher: null,//顾问老师
        classId:null,//班级id
        className:null,//班级名称
        isSignProtpcpl:null,//是否签订协议
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //过滤空数据
      filterArr:[]
    };
  },
  created() {
    this.getList();
  },
    components:{
      Infofile 
   },
  methods: {
     // 当前选中的用户
    celltable (row) {
      this.tablerow = row
    },
    // 关闭模态框的状态
    showbtn (type) {
      this.buttontype[type] = false
    //   this.tablerow = ''
    },
     /* 学生协议 */
    infofile(row){
        // console.log(row)
        this.reset();
        const id = row.id || this.ids
        this.id = id
         Bus.$emit('sendid',this.id)
        this.buttontype.infofile = true
     },
    /** 查询学员档案信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
           let arr =  response.rows.filter(v=>{
                return v.name !== null 
            })
            this.filterArr = arr.filter(v=>{
              switch(v.isSignProtpcpl){
                  case "1":
                      v.isSignProtpcpl = "是"
                      break;
                  case "0":
                      v.isSignProtpcpl = "否"
                      break;
              }
              return v
           }).filter(v=>{
              switch(v.gender){
                  case "1":
                      v.gender = "女"
                      break;
                  case "0":
                      v.gender = "男"
                      break;
              }
              return v
          })       
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id:null,//学员id
        name: null,//姓名
        gender: null,//性别
        idCard: null,//身份证号码
        phone: null,//手机号码
        frontStage: null,//前端阶段
        familyAddress: null,//家庭住址
        birthDate: null,//出生日期
        education: null,//学历
        major: null,//专业
        wechat: null,//微信号
        qq: null,//qq号码
        currentState: null, //目前状态
        city: null,//目标就业城市
        emergencyContact: null,//紧急联系人
        emergencyPhone: null,//紧急联系人电话
        teacher: null,//顾问老师
        classId:null,//班级id
        className:null,//班级名称
        isSignProtpcpl:null,//是否签订协议
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学员档案信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学员档案信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const name = row.name || this.name;
      this.$confirm('是否确认删除学员"' + name + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有学员档案信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
